import type { VbenFormSchema } from '#/adapter/form'
import { EnumLogStatus } from '#/config/enum/system'
import { logStatusOptions, logTypeOptions } from '#/config/options/system'
import { getOptionsLabelByValue } from '#/config/options/utils'
import { $t } from '@vben/locales'

export function getAddEditFormSchema() {
    return [
        {
            fieldName: 'divider-basic',
            label: $t('page.system.children.log.children.operationInfo'),
            defaultValue: '',
            component: 'Divider',
            componentProps: {
                dashed: true
            },
            formItemClass: 'col-span-1 md:col-span-2'
        },
        {
            fieldName: 'title',
            label: $t('page.system.children.log.children.form.title'),
            defaultValue: '',
            component: 'Input'
        },
        {
            fieldName: 'logType',
            label: $t('page.system.children.log.children.form.logType'),
            component: 'Select',
            defaultValue: '',
            componentProps: {
                options: logTypeOptions
            }
        },
        {
            fieldName: 'operationName',
            label: $t('page.system.children.log.children.form.operationName'),
            component: 'Input',
            defaultValue: ''
        },
        {
            label: $t('page.system.children.log.children.form.createTime'),
            fieldName: 'createTime',
            component: 'Input',
            defaultValue: ''
        },
        {
            fieldName: 'divider-basic',
            label: $t('page.system.children.log.children.requestInfo'),
            defaultValue: '',
            component: 'Divider',
            componentProps: {
                dashed: true
            },
            formItemClass: 'col-span-1 md:col-span-2'
        },

        {
            label: $t('page.system.children.log.children.form.operationIp'),
            fieldName: 'operationIp',
            component: 'Input',
            defaultValue: ''
        },
        {
            label: $t('page.system.children.log.children.form.requestMethod'),
            fieldName: 'requestMethod',
            component: 'Input',
            defaultValue: ''
        },

        {
            label: $t('common.status'),
            fieldName: 'status',
            component: 'Switch',
            defaultValue: EnumLogStatus.正常,
            componentProps: {
                checkedChildren: getOptionsLabelByValue(EnumLogStatus.正常, logStatusOptions),
                uncheckedChildren: getOptionsLabelByValue(EnumLogStatus.异常, logStatusOptions),
                checkedValue: EnumLogStatus.正常,
                checkedColor: 'green',
                uncheckedColor: 'red'
            }
        },
        {
            label: $t('page.system.children.log.children.form.spendTime'),
            fieldName: 'spendTime',
            component: (vm: any) => {
                const value = vm.modelValue
                return `${(value || 0) / 1000}s`
            },
            defaultValue: ''
        },
        {
            fieldName: 'operationUrl',
            label: $t('page.system.children.log.children.form.operationUrl'),
            component: 'Input',
            defaultValue: '',
            formItemClass: 'col-span-1 md:col-span-2'
        },
        {
            label: $t('page.system.children.log.children.form.operationMethod'),
            fieldName: 'operationMethod',
            component: 'Input',
            defaultValue: '',
            formItemClass: 'col-span-1 md:col-span-2'
        }
    ] as VbenFormSchema[]
}
